package module4;

import java.io.*;
import java.util.*;

public class chat {
    public static void main(String[] args) {
        //1.定义一个ArrayList集合
        List<String> list = new ArrayList<String>();
        //2.键盘录入字符串
        System.out.println("请输入字符或字符串（输入end结束）：");
        Scanner sc = new Scanner(System.in);
        //3.将输入的字符串转换为流
        BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
        String st = null;
        try {
            while ((st = buffer.readLine()) != null){
                if("end".equals(st))
                    break;
                //4.将录入的字符串添加到ArrayList集合中
                list.add(st);
            }
        } catch (IOException e) {
            throw new RuntimeException("IO异常");
        }
        //5.给ArrayList集合排序，字典倒序
        Collections.sort(list, Collections.reverseOrder());
        //6.将排序好的数据写入abc.txt文件
        PrintWriter pw = null;
        try {
            pw = new PrintWriter("abc.txt");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        for(String i : list){
            pw.println(i);
        }
        pw.close();
    }
}
